package com.fysports.framework.render;

import com.jfinal.ext.kit.RequestWarpper;
import com.jfinal.log.Log;
import com.jfinal.render.RenderFactory;
import com.fysports.framework.exception.FrameException;
import com.fysports.web.module.view.JsonView;


/**
 * Class title:配合ExceptionInterceptor <br/>
 * 分别处理controller中的异常信息(api & web)<br/>
 * Describe: Created by konbluesky<br/>
 * Date : 15/11/27 上午10:18<br/>
 * Project : jdmdataServer<br/>
 */
public class ExpandExceptionRender extends ExceptionRender {
    private static Log logger = Log.getLog(ExpandExceptionRender.class);
    @Override
    public void render() {
        RequestWarpper rw=new RequestWarpper(request);
        //ajax访问或API接口调用时返回json
        if (rw.isMobileReq() || rw.isAjax()) {

            JsonView jv = new JsonView();
            jv.setStatus(false);
            String msg="操作失败!<br/>错误信息:"+getException().getLocalizedMessage();
            jv.setMsg(msg);
            request.setAttribute("ajax_json_msg",msg);
            RenderFactory.me().getJsonRender(jv.toJson()).setContext(request, response).render();
        }else{
            request.setAttribute("errorobj", getException().toString());
            throw new FrameException(getException());
        }

    }

}
